package br.com.projeto.dao.jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import br.com.projeto.sakila.bean.Address;
import br.com.projeto.sakila.bean.Category;
import br.com.projeto.sakila.bean.City;

public class CityDao {
	public long buscarCity(Connection connection){
		long tempoInicial = System.currentTimeMillis();
		
		try {
			PreparedStatement preparedStatement = 
					connection.prepareStatement("select city_id, city, last_update from city");
			
			ResultSet resultSet = preparedStatement.executeQuery();
			List<City> lista = new ArrayList<>();
			City obj;
			while(resultSet.next()){
				obj = null;
				obj = new City();
				obj.setId(Integer.parseInt(resultSet.getString("city_id")));
				obj.setCityMember(resultSet.getString("city"));
				obj.setLastUpdate(resultSet.getDate("last_update"));
				
				lista.add(obj);
			}
			
			resultSet.close();
			preparedStatement.close();
			
		} catch (SQLException exception) {
			System.err.println("Erro JDBC" + exception);
			throw new RuntimeException(exception);
		}
		
		long tempoFinal = System.currentTimeMillis(); 
		long tempo = tempoFinal - tempoInicial;
		return tempo;
	}
}
